package com.china.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.china.osourcechina.R;
import com.china.vo.User;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;

import java.util.ArrayList;

/**
 * Created by jinyaoguang on 2016/5/11.
 */
public class Finduser_Adapter extends BaseAdapter {
    Context context;
    ArrayList<User> list;
    public Finduser_Adapter(ArrayList<User> list, Context context) {
        this.list=list;
        this.context=context;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder h;
        if(convertView==null){
            h=new ViewHolder();
            convertView=View.inflate(context, R.layout.finduser_item,null);
            h.iv_finduser_touxiang= (ImageView) convertView.findViewById(R.id.iv_finduser_touxiang);
            h.iv_finduser_sex= (ImageView) convertView.findViewById(R.id.iv_finduser_sex);
            h.tv_finduser_name= (TextView) convertView.findViewById(R.id.tv_finduser_name);
            h.tv_finduser_from= (TextView) convertView.findViewById(R.id.tv_finduser_from);
            convertView.setTag(h);

        }else{
            h= (ViewHolder) convertView.getTag();
        }

        h.tv_finduser_name.setText(list.get(position).getName());
        h.tv_finduser_from.setText(list.get(position).getFrom());
        //圆角图片
        DisplayImageOptions options = new DisplayImageOptions.Builder()
                .displayer(new RoundedBitmapDisplayer(h.iv_finduser_touxiang.getLayoutParams().height))
                .build();
        //三个参数
        ImageLoader.getInstance().displayImage(list.get(position).getPortrait(), h.iv_finduser_touxiang,options);
//        ImageLoader.getInstance().displayImage(list.get(position).getPortrait(),h.iv_finduser_touxiang);
        if(list.get(position).getGender().equals("男")){
        h.iv_finduser_sex.setImageResource(R.mipmap.userinfo_icon_male);
        }else{
        h.iv_finduser_sex.setImageResource(R.mipmap.userinfo_icon_female);
        }

        return convertView;


    }
    class ViewHolder{
     ImageView iv_finduser_touxiang,iv_finduser_sex;
        TextView tv_finduser_name,tv_finduser_from;
    }
}
